package com.project.weimi.interfaces;

import org.xutils.x;
import org.xutils.common.Callback;
import org.xutils.ex.HttpException;

import android.util.Log;
import android.widget.Toast;


public class MyCallBack<ResultType> implements Callback.CommonCallback<ResultType>{

	@Override
	public void onSuccess(ResultType result) {
		//ToastMessage.showMyToast(x.app(), result.toString());
		Log.e("TAG", "MyCallBack------"+result.toString());
	}

	// 注意:如果是自己onSuccess回调方法里写了一些导致程序崩溃的代码，也会回调该方法，因此可以用以下方法区分是网络错误还是其他错误  
	// 还有一点，网络超时也会报成其他错误，还需具体打印出错误内容比较容易跟踪查看 
	@Override
	public void onError(Throwable ex, boolean isOnCallback) {
		//Toast.makeText(x.app(), ex.getMessage(), Toast.LENGTH_LONG).show();  
		Log.e("TAG", ex.getMessage());
		if (ex instanceof HttpException) { // 网络错误  
			HttpException httpEx = (HttpException) ex;
			int responseCode = httpEx.getCode();  
			String responseMsg = httpEx.getMessage();  
			String errorResult = httpEx.getResult();  
			Log.e("TAG", "网络错误---" + responseCode + "===" + responseMsg + "---" + errorResult);
		} else { // 其他错误  
			
		}
	}

	@Override
	public void onCancelled(CancelledException cex) {
		
	}

	// 不管成功或者失败最后都会回调该接口  
	@Override
	public void onFinished() {
		
	}

}
